// 判断当前组件是否mounted完成
//里是空数组，代表了只有在组件挂载时运行一次
//https://segmentfault.com/a/1190000022990392
import { useCallback, useEffect, useRef } from "react";

export default function useMountedState() :() => boolean{
    const mountedRef = useRef<boolean>(false)
    const get = useCallback(() => mountedRef.current, [])

    useEffect(() => {
      mountedRef.current = true
  
      return () => {
        mountedRef.current = false
      }
    })
  
    return get
}

